<?php
/**
 * 商户后台controll基类
 * @author Administrator
 *
 */
class CControllerMerchantBase extends CControllerBase{
	
	protected $_shopID = 0;
	
	protected $_shopName = "";
	
	protected $_title = "";
	
	function __construct($controller, $action){
		parent::__construct($controller, $action);
		
		$this->checkLogin();
		
		CPage::setPageClass("CPageCustom");
		//$this->sysLog();
	}
	
	/**
	 * 验证登录
	 */
	private function checkLogin()
	{
		if(isset($_SESSION["merchantInfo"]))
		{
			$this->_shopID = $_SESSION["merchantInfo"]["shop_id"];
			$this->_shopName = $_SESSION["merchantInfo"]["shop_name"];
		}
		else
		{
			if($this->getRequestData("isAjax") || $this->getRequestData("isAjax","get"))
			{
				echo -1000;exit;
			}
			$this->redirectUrl("/merchant/account/login");
		}
	}
	
	/**
	 * 记录操作日志
	 */
	private function sysLog()
	{
		/* $stmtLog = new syslogModel();
        $get=json_encode($_GET);
        $post=json_encode($_POST);
        $desc="GET:".$get.",POST:".$post;
        $stmtLog->insert(array(
        	"create_user"=>$this->_userName,
        	"description"=>$desc,
        	"create_time"=>date('Y-m-d H:i:s'),
        	"ip"=>CCommon::getClientIP(),
        	'module_identity'=>$this->_controller,
        	'right_name'=>$this->_action),false
        ); */
	}
	
	
	public function render($viewFile,$param=array(),$masterView="merchant/common/master")
	{
		$model = new shopModel();
		$shopNum = $model->getShopNum();
		$this->setViewParam("shopName",$this->_shopName);
		$this->setViewParam("m_num",$shopNum);
		$this->setViewParam("s_title",$this->_title);
		if($masterView)
		{
			$ext = Config::get("viewSet.ext");
			$this->setViewParam("content","merchant/".$viewFile.$ext);
			parent::render($masterView,$param);
		}
		else
		{
			parent::render("merchant/".$viewFile,$param);
		}
	}
	
	/**
	 * 跳转到提示页面
	 * @param string $msgDetail 提示具体内容
	 * @param int $msgType 消息类型 0成功,1错误,2警告
	 * @param array $links 按钮链接和文字数组 ，格式array(array("text"=>"","href"=>""),array..)，如果为空，则自动显示一个“返回上一页”按钮,
	 * @param bool $auto_redirect 是否倒计时自动跳转
	 */
	protected function sysMsg($msgDetail, $msgType = 0, $links = array(), $autoRedirect = false)
	{
		$this->_validator = null;
		//$this->setMenu("信息提示");
	    if (count($links) == 0)
	    {
	        $links[0]['text'] = "返回上一页";
	        $links[0]['href'] = 'javascript:history.go(-1)';
	    }

	    $array=array('ur_here'=>"系统消息", 'msg_detail'=>$msgDetail, 'msg_type'=>$msgType,
	    	'links'=>$links,'default_url'=>$links[0]['href'],'auto_redirect'=>$autoRedirect);

	    $this->render("common/message",$array);
	    exit;
	}

}